<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("UTF-8");
	response.setContentType("text/html;charset=UTF-8");
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
	String path = request.getContextPath();
%>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title></title>
<link rel="stylesheet" href="<%=path%>/admin/css/pintuer.css">
<link rel="stylesheet" href="<%=path%>/admin/css/admin.css">
<script src="<%=path%>/admin/js/jquery.js"></script>
<script src="<%=path%>/admin/js/pintuer.js"></script>

</head>
<body>
	<form method="post" action="<%=path%>/admin/toUpdate" id="listform">
		<div class="panel admin-panel">
			<div class="panel-head">
				<strong class="icon-reorder">员工列表</strong>
				<td colspan="7" style="text-align: left; padding-left: 20px;"><a
					href="<%=path%>/members/toAdd" class="button border-blue icon-edit"
					style="padding: 5px 15px; margin-left: 30px;"> 新增员工</a>
					<div class="padding border-bottom">
						<ul class="search" style="padding-left: 10px;">
							<!-- <li>
          <input type="text" placeholder="请输入搜索关键字" name="keywords" id="keywords" class="input" style="width:250px; line-height:17px;display:inline-block" />
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a></li> -->
						</ul>
					</div>
					<table class="table table-hover text-center">
						<div id="vos">
							<tr class="thead">
								<th style="width: 10%">姓名</th>
								<th style="width: 8%">部门</th>
								<th style="width: 12%">职务</th>
								<th style="width: 20%">邮箱</th>
								<th width="15%">手机</th>
								<th width="20%">操作</th>
							</tr>
						</div>
						<volist name="list" id="vo"> <c:forEach
							items="${memberList}" var="list" varStatus="s">
							<tr class="fir">
								<input type="hidden" id="id" name="id" value="${list.id}" />
								<td>${list.name }</td>
								<td><c:if test="${list.departmentId eq '1' }">研发部</c:if> <c:if
										test="${list.departmentId eq '2' }">执行部</c:if></td>
								<td>${list.duty }</td>
								<td>${list.email }</td>
								<td>${list.phone }</td>
								<td><div class="button-group" style="height: 44px;">
										<c:if test="${list.deleteState eq '0' }">
											<a class="button border-red"
												onclick="javascript:update(this)">
												<span class="icon-edit"></span>停用</a>
										</c:if>
										<c:if test="${list.deleteState eq '1' }">
											<a class="button border-green"
												onclick="javascript:update(this)">
												<span class="icon-edit"></span>启用</a>
										</c:if>
										</div>
										<div class="button-group" style="height: 44px;">
									        <a class="button border-main"
											onclick="javascript:updateEmp(this)"> 
											<span class="icon-edit"></span> 修改</a>
										</div>
										</td>
							</tr>
						</c:forEach> </volist>
						<tr>
							<td colspan="8">
								<div class="pagelist">
									<a id="up" href="javascript:upPage();">上一页</a>
									<c:forEach begin="1" end="${pageSum }" step="1" var="list"
										varStatus="s">
										<c:if test="${list eq pageNo }">
											<span class="current">${list }</span>
										</c:if>
										<c:if test="${list ne pageNo }">
											<a class="next" href="javascript:void(0);"
												onclick="toPage(this);">${list }</a>
										</c:if>
										<!-- <span class="current">1</span><a  href="">2</a><a href="">3</a> -->
									</c:forEach>
									<a href="javascript:nextPage();">下一页</a>
									<!-- <a href="">尾页</a>  -->
								</div>
							</td>
						</tr>
					</table>
			</div>
	</form>
	<script type="text/javascript" src="<%=path%>/admin/js/layer/layer.js"></script>
	<script type="text/javascript">
	var paths = '<%=path%>';
 	var pageNo = $(".current").text();
 	$(".tag").change(function(){
 		changesearch();
 	});
 	$(function(){
 		var dTag = '${deleteTag}';
 		if(dTag >= 1){
 			layer.msg('删除操作成功！');
 		}else if(dTag == -1){
 			layer.msg('系统忙,请稍后重试...');
 		}
 		var uTag = '${upTag}';
 		if(uTag >= 1){
 			layer.msg('修改操作成功！');
 		}else if(uTag == -1){
 			layer.msg('系统忙,请稍后重试...');
 		}
 	});
//搜索
function changesearch(){	
		newPage(1);
		
}
function nextPage(){
	var pageSum = '${pageSum }';
	pageNo = $(".current").text();
	pageNo = parseInt(pageNo);
	if(pageNo<pageSum){
		pageNo+=1;
	}
	newPage(pageNo);
}
function upPage(){
	pageNo = $(".current").text();
	pageNo = parseInt(pageNo);
	if(pageNo>1){
		pageNo-=1;
	}

	newPage(pageNo);
}
function toPage(obj){
	pageNo = $(obj).text();
	pageNo = parseInt(pageNo);
	newPage(pageNo);
}
//newPage or search
function newPage(pageNo){
	var params = new Object();
	params.pageNo = pageNo-1;
	$.ajax({ 
		type:"post",
		url:"<%=path%>/members/newPage",
		data:params,
		dataType: "json",  
        timeout: 10000,  
        cache: false,  
        error: function(){
        	alert("系统忙...");
        },
        success: function(data){
        	var json=eval(data);
        	pageNo = json.pageNo;
        	pageSum = json.pageSum;
        	var htmls = "";
       	 $.each(json.memberList, function (index, item) {  
             //循环获取数据   
             var record =new Object(); 
            	 record.id=item.id;
            	 record.name=item.name;
            	 record.duty=item.duty;
            	 record.email= item.email;
            	 record.phone = item.phone;
            	 record.departmentId= null;
            	 switch (item.departmentId) {
				case 1:
					record.departmentId = '研发部';
					break;
				case 2:
					record.departmentId = '执行部';
					break;
				default:
					break;
				}
            	 switch (item.deleteState) {
 				case '0':
 					record.deleteState = '停用';
 					break;
 				case '1':
 					record.deleteState = '启用';
 					break;
 				default:
 					break;
 				} 
            	 
               htmls += '<tr class="fir">'
					+'<input type="hidden" id="id" name="id" value="'+record.id+'" />'
					+'<td>'+record.name+'</td>'
					+'<td>'+record.departmentId+'</td>'
					+'<td>'+record.duty+'</td>'
					+'<td>'+record.email+'</td>'
					+'<td>'+record.phone+'</td>'
					htmls+='<td><div class="button-group" style="height: 44px;">'
				if(record.deleteState =='停用'){
					htmls+='<a class="button border-red" onclick="javascript:update(this)"><span class="icon-edit"></span>停用</a>';
				}
					if(record.deleteState =='启用'){
						htmls+='<a class="button border-green" onclick="javascript:update(this)"><span class="icon-edit"></span>停用</a>';
					}	
				htmls+='<a class="button border-main" onclick="javascript:update(this)"><span class="icon-edit"></span>修改</a>';
				htmls+='</div></td>';
			    htmls+='</tr>';
            });
       	 $(".fir").remove();
       	 $(".thead").after(htmls);
       	 //改变页数
       	 $(".next").remove();
       	 $(".current").remove();
       	 var inner = "";
       	 for (var i = 1; i <= pageSum; i++) {
       		 var nowPage = "";
			if(i == pageNo+1){
				nowPage = '<span class="current">'+i+'</span>';
			}else{
				nowPage = '<a class="next"  href="javascript:void(0);" onclick="toPage(this);">'+i+'</a>';
			}
			inner +=nowPage;
		}
       	 $("#up").after(inner);
        }   
	});
}
//修改
function update(obj){
	var id = $(obj).closest(".fir").find("#id").val();
	var state = $(obj).text().trim();
	if(state=="停用"){
		state=1
	}else{
		
		state=0;
	}
	var params = new Object();
	params.id =id;
	params.deleteState = state;
	 $.ajax({ 
		type:"post",
		url:"<%=path%>/members/update",
		data:params,
		dataType: "json",  
        timeout: 10000,  
        cache: false,  
        success: function(data){
        	if(data==1){
        		if(state==1){
            	  layer.msg('停用操作成功！');
            	  $(obj).removeClass("border-red").addClass("border-green");
            	  $(obj).html(' <span class="icon-edit"></span>启用 ');
            	}else{
            	    layer.msg('启用操作成功！');
            	    $(obj).removeClass("border-green").addClass("border-red");
            	    $(obj).html('<span class="icon-edit"></span>停用 ');
            		}	
        		}
        }
    });
}
function updateEmp(obj){
	 var id = $(obj).closest(".fir").find("#id").val();
     window.location.href="<%=path%>/members/toUpdate?Id="+id;
	
	
}


//单个删除
function del(id,mid,iscid){
	if(confirm("您确定要删除吗?")){
		
	}
}

//全选
$("#checkall").click(function(){ 
  $("input[name='id[]']").each(function(){
	  if (this.checked) {
		  this.checked = false;
	  }
	  else {
		  this.checked = true;
	  }
  });
})

//批量删除
function DelSelect(){
	$("#listform").attr("action",paths+"/admin/delete");
	var Checkbox=false;
	 $("input[name='id[]']").each(function(){
	  if (this.checked==true) {		
		Checkbox=true;	
	  }
	});
	if (Checkbox){
		var t=confirm("您确认要删除选中的内容吗？");
		if (t==false) return false;		
		$("#listform").submit();		
	}
	else{
		alert("请选择您要删除的内容!");
		return false;
	}
}
	function addAdmin(){
		window.location.href = "<%=path%>/admin/toAdd";
		}

		function getNowFormatDate(time) {
			var date = new Date(time);
			var seperator1 = "-";
			var seperator2 = ":";
			var year = date.getFullYear();
			var month = date.getMonth() + 1;
			var strDate = date.getDate();
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			if (strDate >= 0 && strDate <= 9) {
				strDate = "0" + strDate;
			}
			var h = 0;
			if (date.getHours() >= 0 && date.getHours() <= 9) {
				h = "0" + date.getHours();
			} else {
				h = date.getHours();
			}
			var m = 0;
			if (date.getMinutes() >= 0 && date.getMinutes() <= 9) {
				m = "0" + date.getMinutes();
			} else {
				m = date.getMinutes();
			}
			var s = 0;
			if (date.getSeconds() >= 0 && date.getSeconds() <= 9) {
				s = "0" + date.getSeconds();
			} else {
				s = date.getSeconds();
			}
			var currentdate = year + seperator1 + month + seperator1 + strDate
					+ " " + h + seperator2 + m + seperator2 + s;
			return currentdate;
		}
	</script>
</body>
<script type="text/javascript" src="<%=path%>/admin/js/layer/layer.js"></script>
<script type="text/javascript">
	
</script>
</html>